
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/25/2012 21:16:34
-- Generated from EDMX file: C:\Users\Mathy\Documents\Codeplex\scms\SimpleCMS\SimpleCMS\Models\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [klavervaerkstedet_dk0_db];
GO
IF SCHEMA_ID(N'SimpleCMS') IS NULL EXECUTE(N'CREATE SCHEMA [SimpleCMS]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[SimpleCMS].[FK_SectionContentArea]', 'F') IS NOT NULL
    ALTER TABLE [SimpleCMS].[ContentAreas] DROP CONSTRAINT [FK_SectionContentArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[FK_ImageCollectionAreaImageArea]', 'F') IS NOT NULL
    ALTER TABLE [SimpleCMS].[ContentAreas_ImageArea] DROP CONSTRAINT [FK_ImageCollectionAreaImageArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[FK_HtmlCollectionAreaHtmlArea]', 'F') IS NOT NULL
    ALTER TABLE [SimpleCMS].[ContentAreas_HtmlArea] DROP CONSTRAINT [FK_HtmlCollectionAreaHtmlArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[FK_SectionSection_Section]', 'F') IS NOT NULL
    ALTER TABLE [SimpleCMS].[SectionSection] DROP CONSTRAINT [FK_SectionSection_Section];
GO
IF OBJECT_ID(N'[SimpleCMS].[FK_SectionSection_Section1]', 'F') IS NOT NULL
    ALTER TABLE [SimpleCMS].[SectionSection] DROP CONSTRAINT [FK_SectionSection_Section1];
GO
IF OBJECT_ID(N'[SimpleCMS].[FK_ImageCollectionArea_inherits_ContentArea]', 'F') IS NOT NULL
    ALTER TABLE [SimpleCMS].[ContentAreas_ImageCollectionArea] DROP CONSTRAINT [FK_ImageCollectionArea_inherits_ContentArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[FK_ImageArea_inherits_ContentArea]', 'F') IS NOT NULL
    ALTER TABLE [SimpleCMS].[ContentAreas_ImageArea] DROP CONSTRAINT [FK_ImageArea_inherits_ContentArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[FK_HtmlCollectionArea_inherits_ContentArea]', 'F') IS NOT NULL
    ALTER TABLE [SimpleCMS].[ContentAreas_HtmlCollectionArea] DROP CONSTRAINT [FK_HtmlCollectionArea_inherits_ContentArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[FK_HtmlArea_inherits_ContentArea]', 'F') IS NOT NULL
    ALTER TABLE [SimpleCMS].[ContentAreas_HtmlArea] DROP CONSTRAINT [FK_HtmlArea_inherits_ContentArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[FK_AddressArea_inherits_ContentArea]', 'F') IS NOT NULL
    ALTER TABLE [SimpleCMS].[ContentAreas_AddressArea] DROP CONSTRAINT [FK_AddressArea_inherits_ContentArea];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[SimpleCMS].[Users]', 'U') IS NOT NULL
    DROP TABLE [SimpleCMS].[Users];
GO
IF OBJECT_ID(N'[SimpleCMS].[Sections]', 'U') IS NOT NULL
    DROP TABLE [SimpleCMS].[Sections];
GO
IF OBJECT_ID(N'[SimpleCMS].[ContentAreas]', 'U') IS NOT NULL
    DROP TABLE [SimpleCMS].[ContentAreas];
GO
IF OBJECT_ID(N'[SimpleCMS].[Settings]', 'U') IS NOT NULL
    DROP TABLE [SimpleCMS].[Settings];
GO
IF OBJECT_ID(N'[SimpleCMS].[ContentAreas_ImageCollectionArea]', 'U') IS NOT NULL
    DROP TABLE [SimpleCMS].[ContentAreas_ImageCollectionArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[ContentAreas_ImageArea]', 'U') IS NOT NULL
    DROP TABLE [SimpleCMS].[ContentAreas_ImageArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[ContentAreas_HtmlCollectionArea]', 'U') IS NOT NULL
    DROP TABLE [SimpleCMS].[ContentAreas_HtmlCollectionArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[ContentAreas_HtmlArea]', 'U') IS NOT NULL
    DROP TABLE [SimpleCMS].[ContentAreas_HtmlArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[ContentAreas_AddressArea]', 'U') IS NOT NULL
    DROP TABLE [SimpleCMS].[ContentAreas_AddressArea];
GO
IF OBJECT_ID(N'[SimpleCMS].[SectionSection]', 'U') IS NOT NULL
    DROP TABLE [SimpleCMS].[SectionSection];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Users'
CREATE TABLE [SimpleCMS].[Users] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Username] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Sections'
CREATE TABLE [SimpleCMS].[Sections] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ContentAreas'
CREATE TABLE [SimpleCMS].[ContentAreas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Section_Id] int  NULL
);
GO

-- Creating table 'Settings'
CREATE TABLE [SimpleCMS].[Settings] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [StyleLocation] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ContentAreas_ImageCollectionArea'
CREATE TABLE [SimpleCMS].[ContentAreas_ImageCollectionArea] (
    [Id] int  NOT NULL
);
GO

-- Creating table 'ContentAreas_ImageArea'
CREATE TABLE [SimpleCMS].[ContentAreas_ImageArea] (
    [Location] nvarchar(max)  NULL,
    [ShortDescription] nvarchar(max)  NULL,
    [LongDescription] nvarchar(max)  NULL,
    [Id] int  NOT NULL,
    [ImageCollectionArea_Id] int  NULL
);
GO

-- Creating table 'ContentAreas_HtmlCollectionArea'
CREATE TABLE [SimpleCMS].[ContentAreas_HtmlCollectionArea] (
    [Id] int  NOT NULL
);
GO

-- Creating table 'ContentAreas_HtmlArea'
CREATE TABLE [SimpleCMS].[ContentAreas_HtmlArea] (
    [Html] nvarchar(max)  NULL,
    [Id] int  NOT NULL,
    [HtmlCollectionArea_Id] int  NULL
);
GO

-- Creating table 'ContentAreas_AddressArea'
CREATE TABLE [SimpleCMS].[ContentAreas_AddressArea] (
    [Address] nvarchar(max)  NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'SectionSection'
CREATE TABLE [SimpleCMS].[SectionSection] (
    [ParentSections_Id] int  NOT NULL,
    [SubSections_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Users'
ALTER TABLE [SimpleCMS].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Sections'
ALTER TABLE [SimpleCMS].[Sections]
ADD CONSTRAINT [PK_Sections]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ContentAreas'
ALTER TABLE [SimpleCMS].[ContentAreas]
ADD CONSTRAINT [PK_ContentAreas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Settings'
ALTER TABLE [SimpleCMS].[Settings]
ADD CONSTRAINT [PK_Settings]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ContentAreas_ImageCollectionArea'
ALTER TABLE [SimpleCMS].[ContentAreas_ImageCollectionArea]
ADD CONSTRAINT [PK_ContentAreas_ImageCollectionArea]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ContentAreas_ImageArea'
ALTER TABLE [SimpleCMS].[ContentAreas_ImageArea]
ADD CONSTRAINT [PK_ContentAreas_ImageArea]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ContentAreas_HtmlCollectionArea'
ALTER TABLE [SimpleCMS].[ContentAreas_HtmlCollectionArea]
ADD CONSTRAINT [PK_ContentAreas_HtmlCollectionArea]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ContentAreas_HtmlArea'
ALTER TABLE [SimpleCMS].[ContentAreas_HtmlArea]
ADD CONSTRAINT [PK_ContentAreas_HtmlArea]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ContentAreas_AddressArea'
ALTER TABLE [SimpleCMS].[ContentAreas_AddressArea]
ADD CONSTRAINT [PK_ContentAreas_AddressArea]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [ParentSections_Id], [SubSections_Id] in table 'SectionSection'
ALTER TABLE [SimpleCMS].[SectionSection]
ADD CONSTRAINT [PK_SectionSection]
    PRIMARY KEY NONCLUSTERED ([ParentSections_Id], [SubSections_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Section_Id] in table 'ContentAreas'
ALTER TABLE [SimpleCMS].[ContentAreas]
ADD CONSTRAINT [FK_SectionContentArea]
    FOREIGN KEY ([Section_Id])
    REFERENCES [SimpleCMS].[Sections]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SectionContentArea'
CREATE INDEX [IX_FK_SectionContentArea]
ON [SimpleCMS].[ContentAreas]
    ([Section_Id]);
GO

-- Creating foreign key on [ImageCollectionArea_Id] in table 'ContentAreas_ImageArea'
ALTER TABLE [SimpleCMS].[ContentAreas_ImageArea]
ADD CONSTRAINT [FK_ImageCollectionAreaImageArea]
    FOREIGN KEY ([ImageCollectionArea_Id])
    REFERENCES [SimpleCMS].[ContentAreas_ImageCollectionArea]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ImageCollectionAreaImageArea'
CREATE INDEX [IX_FK_ImageCollectionAreaImageArea]
ON [SimpleCMS].[ContentAreas_ImageArea]
    ([ImageCollectionArea_Id]);
GO

-- Creating foreign key on [HtmlCollectionArea_Id] in table 'ContentAreas_HtmlArea'
ALTER TABLE [SimpleCMS].[ContentAreas_HtmlArea]
ADD CONSTRAINT [FK_HtmlCollectionAreaHtmlArea]
    FOREIGN KEY ([HtmlCollectionArea_Id])
    REFERENCES [SimpleCMS].[ContentAreas_HtmlCollectionArea]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HtmlCollectionAreaHtmlArea'
CREATE INDEX [IX_FK_HtmlCollectionAreaHtmlArea]
ON [SimpleCMS].[ContentAreas_HtmlArea]
    ([HtmlCollectionArea_Id]);
GO

-- Creating foreign key on [ParentSections_Id] in table 'SectionSection'
ALTER TABLE [SimpleCMS].[SectionSection]
ADD CONSTRAINT [FK_SectionSection_Section]
    FOREIGN KEY ([ParentSections_Id])
    REFERENCES [SimpleCMS].[Sections]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [SubSections_Id] in table 'SectionSection'
ALTER TABLE [SimpleCMS].[SectionSection]
ADD CONSTRAINT [FK_SectionSection_Section1]
    FOREIGN KEY ([SubSections_Id])
    REFERENCES [SimpleCMS].[Sections]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SectionSection_Section1'
CREATE INDEX [IX_FK_SectionSection_Section1]
ON [SimpleCMS].[SectionSection]
    ([SubSections_Id]);
GO

-- Creating foreign key on [Id] in table 'ContentAreas_ImageCollectionArea'
ALTER TABLE [SimpleCMS].[ContentAreas_ImageCollectionArea]
ADD CONSTRAINT [FK_ImageCollectionArea_inherits_ContentArea]
    FOREIGN KEY ([Id])
    REFERENCES [SimpleCMS].[ContentAreas]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'ContentAreas_ImageArea'
ALTER TABLE [SimpleCMS].[ContentAreas_ImageArea]
ADD CONSTRAINT [FK_ImageArea_inherits_ContentArea]
    FOREIGN KEY ([Id])
    REFERENCES [SimpleCMS].[ContentAreas]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'ContentAreas_HtmlCollectionArea'
ALTER TABLE [SimpleCMS].[ContentAreas_HtmlCollectionArea]
ADD CONSTRAINT [FK_HtmlCollectionArea_inherits_ContentArea]
    FOREIGN KEY ([Id])
    REFERENCES [SimpleCMS].[ContentAreas]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'ContentAreas_HtmlArea'
ALTER TABLE [SimpleCMS].[ContentAreas_HtmlArea]
ADD CONSTRAINT [FK_HtmlArea_inherits_ContentArea]
    FOREIGN KEY ([Id])
    REFERENCES [SimpleCMS].[ContentAreas]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'ContentAreas_AddressArea'
ALTER TABLE [SimpleCMS].[ContentAreas_AddressArea]
ADD CONSTRAINT [FK_AddressArea_inherits_ContentArea]
    FOREIGN KEY ([Id])
    REFERENCES [SimpleCMS].[ContentAreas]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------